<?php
class DB
{
/**
* Query ..
*
* @param string $query
* @return string
*/
public function query($query)
{
return $query;
}
}
class User
{
/**
* @var DB
*/
protected $db;
/**
* New User ...
*
* @param DB $db
* @return void
*/
public function __construct($db)
{
$this->db = $db;
}
/**
* Get DB ...
*
* @return DB
*/
protected function getDB()
{
return $this->db;
}
/**
* Use DB Class ...
*
* @return string
*/
public function useDBClass()
{
return $this->getDB()->query('SELECT 1;');
}
}
$db = new DB;
$user = new User($db);
print $user->useDBClass(); // prints 'SELECT 1;' ..
1